# 在你的Django项目的某个app中的tests.py文件中，添加以下测试函数
import sys, os, django, json, random
sys.path.append("项目路径/helloDjango")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'helloDjango.settings')
django.setup()

from django.core import serializers
from django.test import TestCase
from demo.models import Demo


class InsertModelTest(TestCase):

    def test_data_read(self):
        des = Demo.objects.all()
        json_data = serializers.serialize('json', des)
        json_data = json.loads(json_data)
        print(".....", json.dumps(json_data, indent=6))
        # for d in des:
        #     print("这里是测试插入的.....新动态.........",d)
        # self.assertIsNone("a")
        
    def test_data_insert(self):
        characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
        for _ in range(100):
            random_id = ''
            for _ in range(32):
                random_id += random.choice(characters)
            Demo.objects.create(
                id=random_id,
                name="测试",
                region="",
                imgs="",
                date1="2024-12-14T00:00:00Z",
                date2="2024-12-19T00:00:00Z",
                delivery=1,
                classify="",
                resource="abc/CqUnNUhPYMkhZ1wx95sG6RH26E40dYVD/1421365233581.txt",
                remarks="",
                
            )


if __name__ == '__main__':
    print("这里是测试插入的..............")
    InsertModelTest.test_data_insert(None)
    InsertModelTest.test_data_read(None)
    # import django
    # django.setup()
    # from app01 import models  # 根据需要添加该行
 
    # Create your tests here.
